package com.ruoyi.project.mahjong.mapper;

import java.util.Date;
import java.util.List;

import com.ruoyi.project.mahjong.domain.TMember;
import com.ruoyi.project.mahjong.domain.TOpenTable;
import com.ruoyi.project.mahjong.domain.dto.OpenTableDto;
import com.ruoyi.project.mahjong.domain.vo.DeskVo;
import com.ruoyi.project.mahjong.domain.vo.UpgradReportVo;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 新开桌Mapper接口
 *
 * @author ruoyi
 * @date 2023-10-07
 */
public interface TOpenTableMapper
{
    /**
     * 查询新开桌
     *
     * @param id 新开桌ID
     * @return 新开桌
     */
    public TOpenTable selectTOpenTableById(Long id);

    /**
     * 查询新开桌列表
     *
     * @param tOpenTable 新开桌
     * @return 新开桌集合
     */
    public List<TOpenTable> selectTOpenTableList(TOpenTable tOpenTable);

    /**
     * 新增新开桌
     *
     * @param tOpenTable 新开桌
     * @return 结果
     */
    public int insertTOpenTable(TOpenTable tOpenTable);

    /**
     * 修改新开桌
     *
     * @param tOpenTable 新开桌
     * @return 结果
     */
    public int updateTOpenTable(TOpenTable tOpenTable);
    public int updateTOpenTableByBak2(TOpenTable tOpenTable);

    /**
     * 删除新开桌
     *
     * @param id 新开桌ID
     * @return 结果
     */
    public int deleteTOpenTableById(Long id);

    /**
     * 批量删除新开桌
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteTOpenTableByIds(Long[] ids);


    List<TOpenTable>  selectTOpenTableByShopId(@Param("shopId") Long shopId, @Param("tableId")Long tableId);

    Integer insertTOpenTableList(List<TOpenTable> openTable);

    /**
     * 根据订单号查询开桌信息，没有查此桌会员的具体信息
     * @param orderNumber
     * @return
     */
    @Select("select * from  t_open_table  t where t.bak2 =#{orderNumber} GROUP BY t.bak2 ")
    TOpenTable selectTOpenTableByOrderNumber(@Param("orderNumber") String orderNumber);
    @Select("select * from  t_open_table  t where t.bak2 =#{orderNumber} and is_del=0 order by open_start_time")
    List<TOpenTable> selectTOpenTableMemberInfoByOrderNumber(@Param("orderNumber") String orderNumber);
    @Update("update  t_open_table  set  status=1  where bak2 =#{orderNumber}")
    Integer deleteByOrderNumber(String orderNumber);
    @Delete("delete  from  t_open_table t where t.bak2 =#{orderNumber} and member_id = #{id}")
    Integer deleteByOrderNumberAndMemberId(String orderNumber,Long id);
    List<TOpenTable> selectTOpenTableListGroupByShopTableId(Long shopId);

    /**
     * 改变开桌状态
     * @param table
     * @return
     */
    int updateTOpenTableOpenTableStatus(TOpenTable table);

    Integer updateStopStatusByorderNumber( TOpenTable openTable);

    List<TMember> getOpenTableMemberInfo(String orderNumber);

    List<DeskVo> selectTabels(TOpenTable table1);


    List<TOpenTable > selectopenTableList(TOpenTable table1);

    @Update("update t_open_table set status = #{status} where bak2 = #{orderNumber} and status != 3 and is_del = '0'")
    int updateTableStatus(@Param("orderNumber") String orderNumber,@Param("status") String status);

    @Update("update t_open_table t  set is_del=\"1\" where bak2=#{orderNumber}  and member_id=#{memberId}")
    int updateIsDel(@Param("orderNumber") String orderNumber,@Param("memberId") Long memberId);
    @Update("update t_open_table t  set open_start_time=#{openStartTime} , cost_type=#{costType}  where bak2=#{orderNumber} ")
    void changeTableTime(@Param("openStartTime") String openStartTime, @Param("costType")String costType, @Param("orderNumber")String orderSn);
     @Update("update t_open_table t  set remark=#{remark}   where bak2=#{orderNumber}")
    void updateReamrk(@Param("remark") String remark,@Param("orderNumber")  String orderSn);
    @Select("select * from t_open_table where bak2=#{deskId} and member_id=#{memberId} and is_del = '0'")
    TOpenTable selectOne(@Param("deskId") Long deskId, @Param("memberId") Long memberId);


    List<UpgradReportVo> selectReport(@Param("startTime") String startTime, @Param("endTime")String endTime, @Param("shopId") Long shopId);

    @Update("update t_open_table t  set status=1  where bak2=#{orderSn}")
    Long updateStatus(@Param("orderSn") String orderSn);

    @Update("update t_open_table t  set status=1  where table_id=#{tableId}")
    void updateByTableId(@Param("tableId") Long tableId);
}
